package com.weixing.mall.provider.api.model.enums;

import com.weixing.mall.base.enums.IBaseEnum;
import com.weixing.mall.base.utils.EnumUtil;

/**
 * 代理商角色枚举
 *
 * @author siashan
 * @since v2.0
 */

public enum AgentRoleEnum implements IBaseEnum<String> {
    AGENT_DIS_GOLD("AGENT_DIS_GOLD", "金级经销商",35L),
    AGENT_DIS_SILVER("AGENT_DIS_SILVER", "银级经销商",36L),
    AGENT_LV1_GOLD("AGENT_LV1_GOLD", "金级一级代理",37L),
    AGENT_LV1_SILVER("AGENT_LV1_SILVER", "银级一级代理",38L),
    AGENT_LV2_GOLD("AGENT_LV2_GOLD", "金级二级代理",39L),
    AGENT_LV2_SILVER("AGENT_LV2_SILVER", "银级二级代理",40L),
    AGENT_LV3_GOLD("AGENT_LV3_GOLD", "金级三级代理",41L),
    AGENT_LV3_SILVER("AGENT_LV3_SILVER", "银级三级代理",42L),
    ;

    private String value;
    private String desp;
    private Long roleId;

    AgentRoleEnum(String value, String desp,Long roleId) {
        this.value = value;
        this.desp = desp;
        this.roleId = roleId;
    }


    /**
     * 代理等级对应角色
     *
     * @param agentLv   代理等级
     * @param type      代理类型  金级/银级
     * @return 代理角色
     */
    public static AgentRoleEnum getRole(Integer agentLv, Integer type) {
        AgentRoleEnum agentRoleEnum = null;
        AgentLevelEnum agentLevel = EnumUtil.getIEnum(AgentLevelEnum.class, agentLv);
        switch (agentLevel) {
            case DEALER:
                agentRoleEnum = isGold(type) ? AgentRoleEnum.AGENT_DIS_GOLD : AgentRoleEnum.AGENT_DIS_SILVER;
                break;
            case LEVEL_1:
                agentRoleEnum = isGold(type) ? AgentRoleEnum.AGENT_LV1_GOLD : AgentRoleEnum.AGENT_LV1_SILVER;
                break;
            case LEVEL_2:
                agentRoleEnum = isGold(type) ? AgentRoleEnum.AGENT_LV2_GOLD : AgentRoleEnum.AGENT_LV2_SILVER;
                break;
            case LEVEL_3:
                agentRoleEnum = isGold(type) ? AgentRoleEnum.AGENT_LV3_GOLD : AgentRoleEnum.AGENT_LV3_SILVER;
                break;
            default:
                break;
        }
        return agentRoleEnum;
    }

    private static boolean isGold(Integer type) {
        return AgentTypeEnum.GOLD.getValue().equals(type);
    }

    @Override
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String getDesp() {
        return desp;
    }

    public void setDesp(String desp) {
        this.desp = desp;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }
}
